package com.waiter.moximoxi.utils;

import android.content.Context;
import android.media.MediaPlayer;

/**
 * Created by 17639 on 2020/12/24.
 * 播放音频
 */

public class PlayVoice {

    private static MediaPlayer mediaPlayer;

    public static void playVoice(Context context){
        try {
            mediaPlayer= MediaPlayer.create(context, 0);
            mediaPlayer.start();
            mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                @Override
                public void onCompletion(MediaPlayer mp) {
                    mediaPlayer.start();
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    //停止播放声音
    public  static void stopVoice(){
        if(null!=mediaPlayer) {
            mediaPlayer.stop();
        }
    }
}
